const mongoose = require('mongoose');
const config = require('../config');

async function updateSchema() {
  try {
    await mongoose.connect(config.mongodb.url);
    
    // 更新现有文档，添加新字段
    await mongoose.connection.collection('products').updateMany(
      {},
      {
        $set: {
          specification: '',
          unit: '',
          precautions: '',
          purchasePriceDate: null
        }
      }
    );

    console.log('Schema 更新成功');
    process.exit(0);
  } catch (error) {
    console.error('Schema 更新失败:', error);
    process.exit(1);
  }
}

updateSchema(); 